package main

import (
	"go_practice/structs"
	"math"
)

type TreeNode = structs.TreeNode

// BST的最小绝对差，任意不同节点之间的最小差值
// 只会发生在相邻节点之间吧
func getMinimumDifference(root *TreeNode) int {
	var pre int = -1
	var res = math.MaxInt64
	var dfs func(node *TreeNode)
	dfs = func(node *TreeNode) {
		if node == nil {
			return
		}
		dfs(node.Left)

		if pre != -1 && node.Val-pre < res {
			res = node.Val - pre
		}
		pre = node.Val

		dfs(node.Right)
	}
	dfs(root)
	return res
}
